﻿using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using CIAWorldMap;
using MapSurface;

namespace LaoMap
{
    class PlacesRender
    {
        public delegateReport _delegateReport;

        readonly ISurfaceLinear _surface;
        public PlacesRender(Surface surface)
        {
            _surface = surface;
        }

        public void DoPlot2(Dictionary<string, Place> places, Canvas canvas)
        {
            foreach (Place l in places.Values)
            {
                double py = _surface.GetPy(l._Wgs84Coordinate.Latitude);

                if (py > _surface.Height())
                    continue;

                if (py < 0)
                    continue;

                double px = _surface.GetPx(l._Wgs84Coordinate.Longitude);

                if (px > _surface.Width())
                    continue;

                if (px < 0)
                    continue;

                var el = new Ellipse();

                int size = 4;

                if (_surface.XScale > 1000)
                {
                    size = 8;
                }

                el.Height = size;
                el.Width = size;

                //var mySolidColorBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 0));

                // el.Fill = mySolidColorBrush;
                el.StrokeThickness = 0;
                el.Fill = Brushes.Black;

                if (l._population != 0)
                {
                    el.Fill = Brushes.Red;
                    el.Height = 10;
                    el.Width = 10;
                }

                el.Tag = l;

              //  el.MouseDown += new MouseButtonEventHandler(ElMouseDown);
                el.MouseEnter += DebugOnEnter;

                Canvas.SetLeft(el, px - size/2.0);
                Canvas.SetTop(el, py - size / 2.0);
                canvas.Children.Add(el);
            }
        }

        void DebugOnEnter(object o, MouseEventArgs args)
        {
            if (_delegateReport == null)
                return;

            var p = o as Ellipse;
            if (p == null)
                return;
            var place = p.Tag as Place;
            if (place == null)
                return;

            foreach (string t in place._names.Keys)
            {
                _delegateReport("" + t);
            }

            _delegateReport("++++++++++++++++++");
        }

    }
}
